package com.ptswitch.material.dao;

import java.util.Collection;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ptswitch.material.model.material.Material;

public interface MaterialMapper {
    //TODO
    void saveAll(Collection<Material> newMaterials, Collection<Material> oldMaterials, Collection<Material> updateMaterials);

    @Select("select * from material where code=#{code}")
    Material findByCode(@Param("code") String code);

    @Select("select * from material where pcbDecal=#{pcbDecal}")
    List<Material> findByPcbDecal(@Param("pcbDecal") String pcbDecal);

    @Select("select count(*) from material where pcbDecal=#{pcbDecal}")
    public long countByPcbDecal(@Param("pcbDecal") String pcbDecal);

    @Select("select '1' from material where id=1")
    //TODO
    String emptyCode(String code);

    @Select("select * from material where id=#{id}")
    Material findById(@Param("id") long id);

    @Select("select * from material where name like #{like}")
    //TODO
    List<Material> findLike(String like, long first, long size);

    @Select("select count(*) from material where name like #{like}")
    //TODO
    long countLike(@Param("like") String like);

    @Delete("delete from material")
    void deleteAll();

    @Insert("insert material(name)"//
            + " values(#{m.name})")
    //TODO
    void add(@Param("m") Material material);

    @Update("update material set name=#{m.name} where id=#{m.id}")
    //TODO
    void update(@Param("m") Material material);

    @Delete("delete from material where id=#{m.id}")
    void delete(@Param("m") Material material);

    @Select("select * from material")
    //TODO
    List<Material> findLikeByExample(Material example, long first, long size);

    @Select("select * from material")
    //TODO
    long countLikeByExample(Material example);

    @Select("select * from material")
    List<Material> findAll(long first, long size);

    @Select("select count(*) from material")
    long countAll();
}
